package dp;

/**
 * @author pengfei.hpf
 * @date 2020/2/11
 * @verdion 1.0.0
 */
public class NumberOfArithmeticSlices {

    public int numberOfArithmeticSlices(int[] A) {
        if(A == null || A.length < 3){
            return 0;
        }
        int curTotal = 0;
        int curCount = 0;
        int res = 0;
        int lastSub = Integer.MAX_VALUE;
        for(int i = 1; i < A.length; i ++){
            if(A[i]- A[i-1] == lastSub){
                curCount ++;
                curTotal = curTotal + curCount - 2;
            } else {
                res += curTotal;
                curTotal = 0;
                lastSub = A[i] - A[i-1];
                curCount = 2;
            }
        }
        res += curTotal;
        return res;
    }
}
